home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / Gnuplot / Source / term / mif.trm < prev    next >
Encoding:
Text File  |  1993-03-02  |  18.1 KB  |  606 lines

  1. /*
  2.  * $Id: mif.trm%v 3.38.2.68 1993/02/07 00:40:17 woo Exp woo $
  3.  */
  4.  
  5. /* GNUPLOT -- mif.trm */
  6. /*
  7.  * Copyright (C) 1992
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver was developed for
  24.  *      gnuplot for unix version 3.0 (patchlevel 1)
  25.  *      gnuplot for unix version 3.2 (patchlevel 2)
  26.  *
  27.  * This terminal driver supports:
  28.  *      Frame Maker MIF format version 3.00
  29.  *
  30.  * Options for this terminal driver (set terminal mif [options]):
  31.  *      colour /        Draw primitives with line types >= 0 in colour (sep. 2-7)
  32.  *      monochrome      Draw primitives in black (sep. 0)
  33.  *
  34.  *      polyline /      Draw lines as continous curves
  35.  *      vectors         Draw lines as collections of vectors
  36.  *
  37.  *      help / ?        Print short usage description on stderr
  38.  *
  39.  * Properties for this terminal driver:
  40.  *     -Gnuplot size of worksheet:              MIF_XMAX * MIF_YMAX
  41.  *     -Unit in MIF output:                     cm
  42.  *     -Plot primitives with the same pen will
  43.  *      be grouped in the same MIF group.
  44.  *     -Plot primitives with line types >= 0
  45.  *      will as default be drawn in colour.
  46.  *     -Lines are plotted as collections of
  47.  *      vectors, or as continous lines (default)
  48.  *     -Plot primitives in a plot will be in a
  49.  *      Frame in MIF. Several plot Frames will
  50.  *      be collected in one large Frame.
  51.  *     -Point size of MIF output characters:    MIF_PSIZE
  52.  *     -Used font for MIF output characters:    Times
  53.  *
  54.  * AUTHORS:
  55.  *      Olof Franksson, Physics IV, KTH, S-100 44 Stockholm, Sweden
  56.  * 
  57.  * COMMENTS:
  58.  *      Send comments and/or suggestions to olof@fysik4.kth.se
  59.  * 
  60.  */
  61. #if !defined(cfree)
  62. #define cfree free
  63. #endif
  64.  
  65. /** Coordinates **/
  66. #define GNP_TO_MIF(P)   (((float) (P)) / 1000.0)        /* Converts gnuplot units to MIF units */
  67. #define MIF_XMAX 15000                  /* Basic unit: 0.01 mm (15cm -> 15*10*100=15000) */
  68. #define MIF_YMAX 10000                  /* Basic unit: 0.01 mm (10cm -> 10*10*100=10000) */
  69.  
  70. #define MIF_XLAST (MIF_XMAX - 1)
  71. #define MIF_YLAST (MIF_YMAX - 1)
  72.  
  73. static struct mif_line { /* Line point structure specification */
  74.     float fpos_x;           /* Line point X coordinate */
  75.     float fpos_y;           /*            Y coordinate */
  76.     struct mif_line *next;  /* Pointer to next line point */
  77.     struct mif_line *prev;  /* Pointer to previous line point */
  78. } mif_line = { /* Current position structure. Adjust for orign. Local for this file. */
  79.     GNP_TO_MIF(0),
  80.     GNP_TO_MIF(MIF_YLAST),
  81.     &mif_line,
  82.     &mif_line
  83. };
  84.  
  85. /** Characters **/
  86. #define MIF_PSIZE 9                     /* Point size of used characters */
  87.  
  88. #define MIF_VCHAR (MIF_YMAX/25)         /* Distance between rows (a guess) */
  89. #define MIF_HCHAR (MIF_XMAX/100)        /* Distance between characters (a guess) */
  90.  
  91. /** Scale marks **/
  92. #define MIF_VTIC  (MIF_YMAX/150)        /* Size of scale mark (vert) */
  93. #define MIF_HTIC  (MIF_XMAX/225)        /* Size of scale mark (hor) */
  94.  
  95. /** Drawing properties **/
  96. static char mif_justify[64];                    /* How to justify the used text */
  97. static char mif_pen[64], mif_pen_width[64], mif_separation[64];         /* How to plot */
  98.  
  99. #define MIF_NPENS 16                    /* Number of MIF pen types */
  100. static int mif_pentype = 0;             /* Pen type to use. Also used to create groups for graphics */
  101. #define MIF_PEN_TO_GROUP(P)     ( 1 + (P) )     /* Map pen type to group number. Must be >= 1 */
  102.  
  103. /** MIF groups administration **/
  104. #define MIF_NGROUP_ID           20
  105. static struct mif_group_id {
  106.     int group_existance;
  107. #define MIF_GROUP_EXISTS        1       /* This group id should generate a MIF group */
  108. #define MIF_GROUP_NOT_EXISTS    0       /* This group id should not generate a MIF group */
  109.  
  110.     int group_id;
  111. #define MIF_INVALID_GROUP_ID    0       /* An invalid MIF group ID */
  112.  
  113. } mif_group_id[MIF_NGROUP_ID];            /* List of used group ID:s and corresponding MIF groups existance */
  114.  
  115. /** Semaphores **/
  116. static int mif_initialized = 0;        /* != 0 when output is active */
  117. static int mif_in_frame = 0;            /* != 0 when inside a plot frame */
  118. static int mif_frameno = -1;            /* Current frame number */
  119. static int mif_colour = TRUE;           /* == TRUE when colour should be used */
  120. static int mif_polyline = TRUE;         /* == TRUE when lines are drawn as continous curves */
  121.  
  122. /** Declaration of routine/s for internal use **/
  123. static int insert_mif_line(), proc_group_id();
  124.  
  125. /** Routine/s **/
  126.  
  127. /* Called when this terminal type is set in order to parse options */
  128. MIF_options()
  129. {
  130.     extern char term_options[];     /* Declared in ../setshow.c */
  131.  
  132.     if (!END_OF_COMMAND) {
  133.         /* Colour options */
  134.         if (!END_OF_COMMAND && almost_equals(c_token, "m$onochrome")) {    /* Compare up to $ */
  135.             mif_colour = FALSE;
  136.             c_token++;
  137.         }
  138.         if (!END_OF_COMMAND && almost_equals(c_token, "c$olour")) {   /* Compare up to $ */
  139.             mif_colour = TRUE;
  140.             c_token++;
  141.         }
  142.  
  143.         /* Curve options */
  144.         if (!END_OF_COMMAND && almost_equals(c_token, "v$ectors")) {   /* Compare up to $ */
  145.             mif_polyline = FALSE;
  146.             c_token++;
  147.         }
  148.         if (!END_OF_COMMAND && almost_equals(c_token, "p$olyline")) {   /* Compare up to $ */
  149.             mif_polyline = TRUE;
  150.             c_token++;
  151.         }
  152.  
  153.         /* Short help */
  154.         if ( !END_OF_COMMAND &&
  155.              (almost_equals(c_token, "h$elp") ||
  156.               almost_equals(c_token, "?$")) ) { /* Compare up to $ */
  157.             fprintf(stderr, "Usage: set terminal mif [options]\n");
  158.             fprintf(stderr, "\toptions:\n");
  159.             fprintf(stderr, "\t\tcolour /        Draw primitives with line types >= 0 in colour (sep. 2-7)\n");
  160.             fprintf(stderr, "\t\tmonochrome      Draw primitives in black (sep. 0)                        \n");
  161.             fprintf(stderr, "\n");
  162.             fprintf(stderr, "\t\tpolyline /      Draw lines as continous curves                           \n");
  163.             fprintf(stderr, "\t\tvectors         Draw lines as collections of vectors                     \n");
  164.             fprintf(stderr, "\n");
  165.             fprintf(stderr, "\t\thelp / ?        Print short usage description on stderr                  \n");
  166.  
  167.             c_token++;
  168.         }
  169.     }
  170.  
  171.     sprintf(term_options, "%s %s", (mif_colour == TRUE)? "colour": "monochrome",
  172.                        (mif_polyline == TRUE)? "polyline": "vectors");
  173. }
  174.  
  175. /* Set up a MIF output file */
  176. MIF_init()
  177. {
  178.     int i;
  179.  
  180.     extern char version[];        /* Declared in ../version.c */
  181.     extern char patchlevel[];
  182.  
  183.     /* Process if not inside a MIF file and Frame */
  184.     if (mif_initialized == 0 && mif_in_frame == 0) {
  185.         /* Tell this terminal driver that the output is initialized and no current frames are processed */
  186.         mif_initialized = 1;
  187.         mif_in_frame = 0;
  188.  
  189.         /* Reset internal position */
  190.         free_mif_line();
  191.         mif_line.fpos_x = GNP_TO_MIF(0);
  192.         mif_line.fpos_y = GNP_TO_MIF(MIF_YLAST);
  193.  
  194.         /* Reset drawing properties strings */
  195.         mif_pen[0] = '\0';
  196.         mif_pen_width[0] = '\0';
  197.         mif_separation[0] = '\0';
  198.         sprintf(mif_justify, " <TLAlignment Left> ");
  199.  
  200.         /* Reset group ID generator */
  201.         for (i = 0; i < MIF_NGROUP_ID; i++) {
  202.             mif_group_id[i].group_id = MIF_INVALID_GROUP_ID;
  203.             mif_group_id[i].group_existance = MIF_GROUP_NOT_EXISTS;
  204.         }
  205.  
  206.         /* Identify ourselves */
  207.         fprintf(outfile, "<MIFFile 3.00> # Generated by gnuplot version %s patchlevel %s; identifies this as a MIF file\n", version, patchlevel);
  208.         fprintf(outfile, "#\n");
  209.  
  210.         /* Setup a default environment to use */
  211.         fprintf(outfile, "# Set a default pen pattern, pen width, unit and font for subsequent objects\n");
  212.         fprintf(outfile, "<Pen 0>\n");
  213.         fprintf(outfile, "<Fill 15>\n");
  214.         fprintf(outfile, "<PenWidth 0.5 pt>\n");
  215.         fprintf(outfile, "<Separation 0>\n");
  216.         fprintf(outfile, "<Units Ucm>\n");
  217.         fprintf(outfile, "<Font <FFamily `Times'> <FSize %d> <FPlain Yes>>\n", MIF_PSIZE);
  218.         fprintf(outfile, "#\n");
  219.     } /* MIF file created */
  220. }
  221.  
  222. /* Finish of a MIF output file */
  223. MIF_reset()
  224. {
  225.     /* Process if inside a MIF file and not inside a Frame */
  226.     if (mif_initialized != 0 && mif_in_frame == 0) {
  227.         /* Finish off the MIF file */
  228.         fprintf(outfile, "#\n");
  229.         fprintf(outfile, "# End of MIFFile\n");
  230.  
  231.         /* Tell this terminal driver that the output is finished */
  232.         mif_initialized = 0;
  233.     } /* MIF file finished */
  234. }
  235.  
  236. /* Start plotting a Frame (-> graphics mode) */
  237. MIF_graphics()
  238. {
  239.     int i;
  240.  
  241.     /* Process if not inside a Frame */
  242.     if (mif_initialized != 0 && mif_in_frame == 0) {
  243.         /* Tell that this terminal driver is working with a plot frame */
  244.         mif_in_frame = 1;
  245.  
  246.         /* Update frame number */
  247.         mif_frameno++;
  248.  
  249.         /* Set current position */
  250.         free_mif_line();
  251.         mif_line.fpos_x = GNP_TO_MIF(0);
  252.         mif_line.fpos_y = GNP_TO_MIF(MIF_YLAST);
  253.  
  254.         /* Set drawing properties */
  255.         mif_pen[0] = '\0';
  256.         mif_pen_width[0] = '\0';
  257.         mif_separation[0] = '\0';
  258.         sprintf(mif_justify, " <TLAlignment Left> ");
  259.  
  260.         /* Reset group ID generator */
  261.         for (i = 0; i < MIF_NGROUP_ID; i++) {
  262.             mif_group_id[i].group_id = MIF_INVALID_GROUP_ID;
  263.             mif_group_id[i].group_existance = MIF_GROUP_NOT_EXISTS;
  264.         }
  265.  
  266.         /* Frame preamble */
  267.         fprintf(outfile, "#\n");
  268.         fprintf(outfile, "# Frame number %d with plot of graphics\n", mif_frameno);
  269.         fprintf(outfile, "<Frame\n");
  270.         fprintf(outfile, "\t<Pen 15>\n");
  271.         fprintf(outfile, "\t<Fill 15>\n");
  272.         fprintf(outfile, "\t<PenWidth  0.5 pt>\n");
  273.         fprintf(outfile, "\t<Separation 0>\n");
  274.         fprintf(outfile, "\t<BRect 0.000 %.3f %.3f %.3f>\n",
  275.                  ((float) mif_frameno)*GNP_TO_MIF(MIF_YMAX+100), GNP_TO_MIF(MIF_XMAX), GNP_TO_MIF(MIF_YMAX));
  276.         fprintf(outfile, "\t<NSOffset  0.000>\n");
  277.         fprintf(outfile, "\t<BLOffset  0.000>\n");
  278.     } /* Frame created */
  279. }
  280.  
  281. /* Stop plotting a Frame (-> text mode) */
  282. MIF_text()
  283. {
  284.     int i;
  285.  
  286.     /* Process if inside a Frame */
  287.     if (mif_initialized != 0 && mif_in_frame != 0) {
  288.  
  289.         /* Draw pending line */
  290.         if (mif_polyline == TRUE)
  291.             put_mif_line();
  292.  
  293.         /* Group the used plot primitives */
  294.         fprintf(outfile, "\t#\n");
  295.         fprintf(outfile, "\t# Group the the objects in groups to make the chart easier to manipulate\n");
  296.         fprintf(outfile, "\t# after it's imported into FrameMaker.\n");
  297.  
  298.         for (i = 0; i < MIF_NGROUP_ID; i++) {
  299.             if (mif_group_id[i].group_id != MIF_INVALID_GROUP_ID &&
  300.                 mif_group_id[i].group_existance == MIF_GROUP_EXISTS) {
  301.                 fprintf(outfile, "\t<Group\n");
  302.                 fprintf(outfile, "\t\t<ID %d>\n", mif_group_id[i].group_id);
  303.                 fprintf(outfile, "\t>\n");
  304.             }
  305.         }
  306.  
  307.         /* Frame post amble */
  308.         fprintf(outfile, ">\n");
  309.         fprintf(outfile, "# End of Frame number %d\n", mif_frameno);
  310.         fprintf(outfile, "#\n");
  311.  
  312.         /* Tell that this terminal driver is not working with a plot frame */
  313.         mif_in_frame = 0;
  314.     } /* Frame finshed */
  315. }
  316.  
  317. /* Select type of line in grapics */
  318. /* NOTE: actually written to output the first time a primitive is drawn AFTER this call */
  319. MIF_linetype(linetype)
  320. int linetype;           /* -2=border, -1=X/Y-axis, 0-13=lines, and 14-=mapped back */
  321. {
  322.     /* Process if inside a Frame */
  323.     if (mif_initialized != 0 && mif_in_frame != 0) {
  324.  
  325.         /* Draw pending line */
  326.         if (mif_polyline == TRUE)
  327.             put_mif_line();
  328.  
  329.         /* Translate gnuplot pen types to MIF pen types */
  330.         if (linetype < 0) {     /* Special lines */
  331.             if (linetype == -1) {
  332.                 mif_pentype = 8+MIF_NPENS;      /* -1 */
  333.                 if (mif_colour == TRUE)
  334.                     sprintf(mif_separation, " <Separation 0> ");
  335.             }
  336.             else {
  337.                 mif_pentype = 0+MIF_NPENS;      /* -2 or less */
  338.                 if (mif_colour == TRUE)
  339.                     sprintf(mif_separation, " <Separation 0> ");
  340.             }
  341.             sprintf(mif_pen_width, " <PenWidth 1.0 pt> ");
  342.         }
  343.         else {                  /* Normal lines */
  344.             mif_pentype = (linetype)%MIF_NPENS;     /* 0-(MIF_NPENS-1) */
  345.             sprintf(mif_pen_width, " <PenWidth 0.5 pt> ");
  346.             if (mif_colour == TRUE)
  347.                 sprintf(mif_separation, " <Separation %d> ", 2+(mif_pentype%6));        /* 2-7 */
  348.         }
  349.  
  350.         /* Set pen type */
  351.         sprintf(mif_pen, " <Pen %d> ", (mif_pentype%MIF_NPENS));
  352.  
  353.     } /* Primitive processed */
  354. }
  355.  
  356. /* Justify following text lines (MIF_put_text()) relative to the insertion point */
  357. MIF_justify_text(mode)
  358. /* NOTE: actually written to output in text primitives which are drawn AFTER this call */
  359. enum JUSTIFY mode;
  360. {
  361.     int rval = TRUE;
  362.  
  363.     /* Process if inside a Frame */
  364.     if (mif_initialized != 0 && mif_in_frame != 0) {
  365.         switch (mode) {
  366.         case LEFT:
  367.             sprintf(mif_justify, " <TLAlignment Left> ");
  368.             break;
  369.         case CENTRE:
  370.             sprintf(mif_justify, " <TLAlignment Center> ");
  371.             break;
  372.         case RIGHT:
  373.             sprintf(mif_justify, " <TLAlignment Right> ");
  374.             break;
  375.         default:
  376.             rval = FALSE;
  377.             break;
  378.         }
  379.  
  380.     } /* Primitive processed */
  381.     else {
  382.         rval = FALSE;
  383.     }
  384.  
  385.     return(rval);
  386. }
  387.  
  388. /* Draw a vector from current position to (x, y) and change current position. */
  389. /* NOTE: actually written to output the first time another primitive is called AFTER this call */
  390. MIF_vector(x, y)
  391. unsigned int x, y;
  392. {
  393.     /* Process if inside a Frame */
  394.     if (mif_initialized != 0 && mif_in_frame != 0) {
  395.  
  396.         /* Setup the vector as a part of the line */
  397.         insert_mif_line(GNP_TO_MIF(x), GNP_TO_MIF(MIF_YLAST-y));
  398.  
  399.         /* Draw pending line -> vector */
  400.         if (mif_polyline == FALSE)
  401.             put_mif_line();
  402.  
  403.     } /* Vector processed */
  404. }
  405.  
  406. /* Move current position */
  407. MIF_move(x, y)
  408. unsigned int x, y;
  409. {
  410.     /* Process if inside a Frame */
  411.     if (mif_initialized != 0 && mif_in_frame != 0) {
  412.  
  413.         /* Draw pending line */
  414.         if (mif_polyline == TRUE)
  415.             put_mif_line();
  416.  
  417.         mif_line.fpos_x = GNP_TO_MIF(x);
  418.         mif_line.fpos_y = GNP_TO_MIF(MIF_YLAST-y);
  419.     }
  420. }
  421.  
  422. /* Draw the text string str at (x, y). Adjust according to MIF_justify_text(). Change current position. */
  423. MIF_put_text(x, y, str)
  424. unsigned int x, y;
  425. char str[];
  426. {
  427.     /* Process if inside a Frame */
  428.     if (mif_initialized != 0 && mif_in_frame != 0) {
  429.  
  430.         /* Draw pending line */
  431.         if (mif_polyline == TRUE)
  432.             put_mif_line();
  433.  
  434.         /* Adjust current position for text-graphics alignment */
  435.         MIF_move(x, y-MIF_VCHAR/5);
  436.  
  437.         if (strlen(str) > 0) {
  438.  
  439.             /* Draw the text */
  440.             fprintf(outfile, "\t<TextLine <GroupID %d> %s %s %s\n",
  441.                      MIF_PEN_TO_GROUP(mif_pentype), mif_pen, mif_pen_width, mif_separation);
  442.             fprintf(outfile, "\t\t<TLOrigin  %.3f %.3f> %s <String `%s'>\n",
  443.                     mif_line.fpos_x, mif_line.fpos_y, mif_justify, str);
  444.             fprintf(outfile, "\t>\n");
  445.  
  446.             /* Register the used group ID */
  447.             proc_group_id(MIF_PEN_TO_GROUP(mif_pentype));
  448.  
  449.             /* Avoid to redraw this. The MIF system should remember it. */
  450.             mif_pen[0] = '\0';
  451.             mif_pen_width[0] = '\0';
  452.             mif_separation[0] = '\0';
  453.  
  454.             mif_justify[0] = '\0';  /* Independent of linetype */
  455.         }
  456.     } /* Text processed */
  457. }
  458.  
  459. /* Draw the pending line. Change current position. */
  460. static int put_mif_line()
  461. {
  462.     int np, i;
  463.     struct mif_line *tline;
  464.  
  465.     /* Process if inside a Frame */
  466.     if (mif_initialized != 0 && mif_in_frame != 0) {
  467.  
  468.         /* Count the number of available points */
  469.         for (tline = mif_line.next, np = 1; tline != &mif_line; tline = tline->next, np++)
  470.             ;
  471.  
  472.         /* Draw line (at least two points) */
  473.         if (np >= 2) {
  474.             /* Line preamble */
  475.             fprintf(outfile, "\t<PolyLine <GroupID %d> %s %s %s\n",
  476.                      MIF_PEN_TO_GROUP(mif_pentype), mif_pen, mif_pen_width, mif_separation);
  477.  
  478.             /* Draw the line elements */
  479.             fprintf(outfile, "\t\t<NumPoints %d> ", np);
  480.             for (i = 0, tline = &mif_line; i < np; i++, tline = tline->next) {
  481.                 if (i%4 == 0)
  482.                     fprintf(outfile, "\n\t\t");
  483.                 fprintf(outfile, "<Point  %.3f %.3f> ", tline->fpos_x, tline->fpos_y);
  484.             }
  485.  
  486.             /* Line post amble */
  487.             fprintf(outfile, "\n\t>\n");
  488.  
  489.             /* Register the used group ID */
  490.             proc_group_id(MIF_PEN_TO_GROUP(mif_pentype));
  491.  
  492.             /* Avoid to redraw this. The MIF system should remember it. */
  493.             mif_pen[0] = '\0';
  494.             mif_pen_width[0] = '\0';
  495.             mif_separation[0] = '\0';
  496.  
  497.             /* Move current position to end of line */
  498.             mif_line.fpos_x = mif_line.prev->fpos_x;
  499.             mif_line.fpos_y = mif_line.prev->fpos_y;
  500.  
  501.             /* Restore the line */
  502.             free_mif_line();
  503.         }
  504.  
  505.     } /* Line processed */
  506. }
  507.  
  508. /* Insert one point in the line */
  509. static int insert_mif_line(fx, fy)
  510. float fx, fy;
  511. {
  512.     int rval = TRUE;
  513.  
  514.     if ((mif_line.prev->next = (struct mif_line *) alloc(sizeof(struct mif_line),"MIF driver")) != (struct mif_line *) NULL) {
  515.         /* Link */
  516.         mif_line.prev->next->next = &mif_line;
  517.         mif_line.prev->next->prev = mif_line.prev;
  518.         mif_line.prev = mif_line.prev->next;
  519.  
  520.         /* Fill */
  521.         mif_line.prev->fpos_x = fx;
  522.         mif_line.prev->fpos_y = fy;
  523.  
  524.         rval = TRUE;
  525.     }
  526.     else { /* Failed to allocate */
  527.         /* Relink */
  528.         mif_line.prev->next = &mif_line;
  529.  
  530.         rval = FALSE;
  531.     }
  532.  
  533.     return(rval);
  534. }
  535.  
  536. /* Deallocate the used line structure elements */
  537. static int free_mif_line()
  538. {
  539.     struct mif_line *tline;
  540.  
  541.     while (mif_line.prev != &mif_line) {
  542.         /* Unlink */
  543.         tline = mif_line.prev;
  544.         mif_line.prev = mif_line.prev->prev;
  545.         mif_line.prev->next = &mif_line;
  546.  
  547.         /* Deallocate */
  548.         free(tline);
  549.     }
  550.  
  551.     /* Make sure that the list will be empty */
  552.     mif_line.prev = &mif_line;
  553.     mif_line.next = &mif_line;
  554. }
  555.  
  556. /* Register group ID. Update group ID existance. */
  557. /* Returns:     1       group_id belongs to a MIF group
  558.         0       group_id does not belong to a MIF group
  559.            -1       not inside a Frame
  560.            -2       group ID list is full
  561.  */
  562. static int proc_group_id(group_id)
  563. int group_id;
  564. {
  565.     int i, rval = 0;
  566.  
  567.     /* Process if inside a Frame */
  568.     if (mif_initialized != 0 && mif_in_frame != 0) {
  569.  
  570.         /* Find out the group ID, or a free group ID slot index. */
  571.         for (i = 0; i < MIF_NGROUP_ID &&
  572.                 mif_group_id[i].group_id != MIF_INVALID_GROUP_ID &&
  573.                 mif_group_id[i].group_id != group_id;
  574.                                         i++) {
  575.             /* Don't check the group_existance variable */
  576.         }
  577.  
  578.         if (i < MIF_NGROUP_ID) {
  579.             if (mif_group_id[i].group_id == MIF_INVALID_GROUP_ID) {
  580.                 /* Register as new group ID for eventual use as MIF group */
  581.                 mif_group_id[i].group_id = group_id;
  582.                 mif_group_id[i].group_existance = MIF_GROUP_NOT_EXISTS;
  583.             }
  584.             else {
  585.                 /* If second use of this group ID -> create a new MIF group */
  586.                 if (mif_group_id[i].group_id == group_id) {
  587.                     mif_group_id[i].group_existance = MIF_GROUP_EXISTS;
  588.                     /* NOTE: a group MUST have at least two members. */
  589.                     rval = 1;
  590.                 }
  591.             }
  592.         }
  593.         else {
  594.             rval = -2;      /* No place for this group ID in the list */
  595.         }
  596.  
  597.     } /* Group ID processed */
  598.     else {
  599.         rval = -1;      /* Not inside a Frame */
  600.     }
  601.  
  602.     /* Return MIF group status */
  603.     return(rval);
  604. }
  605.  
  606.